#include <crow.h>
#include<iostream>
#include <string>

int main() {
    // 创建Crow应用实例
    crow::SimpleApp app;

    // 主页路由 - 返回一个简单的HTML页面
    CROW_ROUTE(app, "/")
    ([](){
        crow::response res;
        res.set_header("Content-Type", "text/html; charset=utf-8");
        
        // HTML内容
        std::string html = R"(
            <!DOCTYPE html>
            <html>
            <head>
                <title>简单Crow页面</title>
                <style>
                    body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
                    h1 { color: #2c3e50; }
                    .container { text-align: center; margin-top: 50px; }
                    .links { margin-top: 30px; }
                    a { color: #3498db; margin: 0 10px; text-decoration: none; }
                    a:hover { text-decoration: underline; }
                </style>
            </head>
            <body>
                <div class="container">
                    <h1>欢迎使用Crow框架</h1>
                    <p>这是一个使用Crow库创建的简单网页示例</p>
                    <div class="links">
                        <a href="/about">关于</a>
                        <a href="/greet/访客">问候</a>
                    </div>
                </div>
            </body>
            </html>
        )";
        
        res.write(html);
        return res;
    });

    // 关于页面路由
    CROW_ROUTE(app, "/about")
    ([](){
        crow::response res;
        res.set_header("Content-Type", "text/html; charset=utf-8");
        
        std::string html = R"(
            <!DOCTYPE html>
            <html>
            <head>
                <title>关于 - Crow示例</title>
                <style>
                    body { font-family: Arial, sans-serif; padding: 20px; }
                    a { color: #3498db; text-decoration: none; }
                    a:hover { text-decoration: underline; }
                </style>
            </head>
            <body>
                <h1>关于本页面</h1>
                <p>hello world</p>
                <p>Crow是一个轻量级的C++ Web框架，语法类似Python的Flask。</p>
                <p><a href="/">返回首页</a></p>
            </body>
            </html>
        )";
        
        res.write(html);
        return res;
    });

    // 带参数的路由 - 问候页面
    CROW_ROUTE(app, "/greet/<string>")
    ([](std::string name){
        crow::response res;
        res.set_header("Content-Type", "text/html; charset=utf-8");
        
        std::string html = R"(
            <!DOCTYPE html>
            <html>
            <head>
                <title>问候 - Crow示例</title>
                <style>
                    body { font-family: Arial, sans-serif; padding: 20px; }
                    a { color: #3498db; text-decoration: none; }
                    a:hover { text-decoration: underline; }
                </style>
            </head>
            <body>
                <h1>你好，)" + name + R"(！</h1>
                <p>这是一个带参数的路由示例</p>
                <p><a href="/">返回首页</a></p>
            </body>
            </html>
        )";
        
        res.write(html);
        return res;
    });

    // 启动服务器，监听8080端口
    std::cout << "服务器启动，访问 http://localhost:8080" << std::endl;
    app.port(8080).multithreaded().run();
    
    return 0;
}